'''
CodeJam Practice 
Created on 2012-12-20

@author: festony
'''

from cj_lib import *
from properties import *

import math
import fractions


#curr_file_name = 'A-large-practice'
#curr_file_name = 'A-small-practice'
curr_file_name = 'test'

# map(int, input_lines.pop(0).split(' '))

def input_dividing_func(input_lines):
    total_case = int(input_lines.pop(0))
    case_inputs = []
    for i in range(total_case):
        input1 = input_lines.pop(0).split(' ')
        print input1
        t = int(input1.pop(0))
        input2 = []
        for j in range(t):
            c = input1.pop(0)
            p = int(input1.pop(0))
            input2.append([c, p])
        case_inputs.append(input2)
    return case_inputs
    
def process_func(func_input):
    print func_input
    seq = func_input
    o = [0, 1]
    b = [0, 1]
    t = 0
    for s in seq:
        c = []
        if s[0] == 'O':
            c = o
        else:
            c = b
        d = int(math.fabs(c[1] - s[1]))
        #print d, t, c
        c[0] += d
        c[1] = s[1]
        if t > c[0]:
            c[0] = t
        else:
            t = c[0]
        t += 1
        c[0] += 1
        #print s[0], c
        #print o, b
    
    
    return t

run_proc(process_func, input_dividing_func, curr_working_folder, curr_file_name)


